# Copyright 2007 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


"""Linux implementations of platform-specific utilities and pseudo-constants

Certain functions must be implemented in OS-specific ways due to differences
between Linux and Windows.  The constants and functions defined here are
imported into a common interface by platform.py.

"""


import os
import pwd
import shutil
import sys

from errno import ENOENT


# See nt.py for an explanation of why ENOENT_codes is needed.
ENOENT_codes = [ENOENT]
DEFAULT_EDITOR_COMMAND = 'vi'


def DescribeSubprocessError(cmd, status):
  """Return a string describing an error returned by a subprocess.

  Arguments:
    cmd    -- the name or description of the command that was executed
    status -- the status code returned by the executed command

  """

  if os.WIFEXITED(status):
    msg = "'%s' exited %d" % (cmd, os.WEXITSTATUS(status))
  elif os.WIFSIGNALED(status):
    msg = "'%s' killed with signal %d" % (cmd, os.WTERMSIG(status))
  elif os.WIFSTOPPED(status):
    msg = "'%s' stopped with signal %d" % (cmd, os.WSTOPSIG(status))
  else:
    msg = "'%s' exited with invalid status (%d)" % (cmd, status)
  return msg


# Works fine on unix.
rmtree = shutil.rmtree


def GetUserName():
  """Return the current user's local username."""
  return pwd.getpwuid(os.getuid())[0]


def ExecutableNames(short_name):
  """Return a list of potential executable names based on the given short name.

  Arguments:
    short_name -- a candidate executable name, with no "dot" extension

  Returns:
    A list containing only the unchanged short name.

  """

  return [short_name]


def EditorWantsBOM(editor, encoding):
  return False


def GetSvnUserConfigDir():
  return os.path.expanduser(os.path.join('~','.subversion'))
def GetSvnSystemConfigDir():
  return '/etc/subversion'
def GetGvnUserConf():
  return os.path.expanduser(os.path.join('~','.gvn'))
def GetGvnSystemConf():
  return '/etc/gvn'
